package enumdemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-10-10
 * Time: 17:50
 */
public enum TestEnum {
    RED(0, "RED"), WHITE(1, "WHITE"),
    GREEN(2, "GREEN"), BLACK(3, "BLACK");
    public int ordinal;
    public String color;

    TestEnum(int ordinal, String color) {
        this.ordinal = ordinal;
        this.color = color;
    }

    public static void main(String[] args) {
        TestEnum[] testEnums = TestEnum.values();

        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i] + " " + testEnums[i].ordinal());
        }

        TestEnum testEnum = TestEnum.valueOf("BLACK");
        System.out.println(testEnum);// BLACK

        System.out.println(GREEN.compareTo(RED));// 2
    }
    //1. switch语句
    public static void main1(String[] args) {
        TestEnum testEnum = RED;
        switch (testEnum) {
            case RED:
                System.out.println("RED");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            case WHITE:
                System.out.println("WHITE");
                break;
            default:
                System.out.println("无法匹配！！！");
                break;

        }
    }
}
